package com.liyujie.networkrequest.pop;

import android.content.Context;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.dyhdyh.support.countdowntimer.CountDownTimerSupport;
import com.dyhdyh.support.countdowntimer.OnCountDownTimerListener;
import com.liyujie.networkrequest.R;
import com.lxj.xpopup.core.CenterPopupView;

public class DoorOpenPopup extends CenterPopupView {
    /**
     *
     */
    private int boxNum;
    /**
     * 倒计时
     */
    private CountDownTimerSupport mCountDownTimerSupport = new CountDownTimerSupport(5000,1000);

    public DoorOpenPopup(@NonNull Context context) {
        super(context);
    }

    public DoorOpenPopup(@NonNull Context context,int boxNum) {
        super(context);
        this.boxNum = boxNum;
    }

    @Override
    protected int getImplLayoutId() {

        return R.layout.popup_door_open;

    }


    @Override
    protected void onCreate() {
        super.onCreate();
        //门号
        TextView tv_open = findViewById(R.id.tv_open);
        tv_open.setText(boxNum + "号已开启");
        //倒计时
        TextView tv_countDown = findViewById(R.id.tv_countDown);

        //倒计时监听
        mCountDownTimerSupport.setOnCountDownTimerListener(new OnCountDownTimerListener() {
            @Override
            public void onTick(long millisUntilFinished) {
                tv_countDown.setText(millisUntilFinished / 1000 + "s");
            }

            @Override
            public void onFinish() {
                try {
                    dismiss();
                }catch (Exception e){
                    e.getMessage();
                }
            }
        });
        /**
         * 重置时间
         */
        ResetTime();
    }


    /**
     * 重置时间
     */
    protected void ResetTime(){
        if(null != mCountDownTimerSupport){
            mCountDownTimerSupport.reset();
            mCountDownTimerSupport.start();
        }
    }

    /**
     * 重置暂停
     */
    protected void ResetPause(){
        if(null != mCountDownTimerSupport){
            mCountDownTimerSupport.reset();
            mCountDownTimerSupport.pause();
        }
    }

}
